package kit.edu.lego.gruppe3.levels.treeArea.old;

import kit.edu.lego.gruppe3.ComponentsRepository;
import kit.edu.lego.gruppe3.actions.Movement;
import kit.edu.lego.gruppe3.levels.LevelSelector;
import kit.edu.lego.gruppe3.levels.LevelSelector.Level;
import kit.edu.lego.gruppe3.sensors.Scanner;
import lejos.robotics.subsumption.Behavior;
import lejos.util.Delay;

public class LeftTurnController implements Behavior {

	private double length = ComponentsRepository.VEHICLE_LENGTH;

	@Override
	public void action() {
		Movement.turnCenter(-90);
		Movement.travel(length, 10);
		if (Scanner.getRangeAt(90, true) >= 30) {
			Movement.travel(-length, 10);
			TreeAreaSolver.setStatus(TreeAreaState.treeFoundRight);
		} else if (Scanner.getRangeAt(0, true) < 30) {
			Movement.turnCenter(-90);
			TreeAreaSolver.setStatus(TreeAreaState.searchForTreeLeft);
		} else {
			Movement.turnCenter(-90);
			TreeAreaSolver.setStatus(TreeAreaState.searchForTreeRight);
		}

	}

	@Override
	public void suppress() {
	}

	@Override
	public boolean takeControl() {
		return Level.treeArea == LevelSelector.getInstance().getCurrentLevel()
				&& TreeAreaState.searchForTreeLeft == TreeAreaSolver
						.getStatus() && Scanner.getRangeAt(0, true) < 30;
	}

}